<template>
  <div class="store-permission">
    <div class="search-content">
      <span class="fs16"></span>
      <el-input v-model="searchObj.store_name" placeholder="请输入经销商名称" clearable class="input w200"></el-input>
      <el-input v-model="searchObj.member_name" placeholder="请输入账号名称" clearable class="input w200"></el-input>
      <el-input v-model="searchObj.store_owner" placeholder="请输入公司名称" clearable class="input w200"></el-input>
         <el-select v-model="searchObj.depart_id" placeholder="请选择所属集团">
        <el-option
          v-for="item in group"
          :key="item.depart_id"
          :label="item.depart_name"
          :value="item.depart_id">
        </el-option>
      </el-select>
      <el-button type="primary" @click="search">搜索</el-button>
      <el-button type="primary" @click="reset">重置</el-button>
    </div>
    <div class="agentList" style="width:100%;">
      <el-table
        :data="aList"
        border
        style="width: 100%"
        ref="table"
        :height="oHeight"
        :header-cell-style="{'text-align':'center'}"
        :cell-style="{'text-align':'center'}"
      >
        <el-table-column fixed prop="store_id" label="店铺ID" key="store_id"></el-table-column>
        <el-table-column
          prop="first_depart_name"
          label="所属集团"
          key="first_depart_name"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="store_name"
          label="经销商名称"
          key="store_name"
          min-width="120"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="store_owner"
          label="公司名称"
          key="store_owner"
          :show-overflow-tooltip="true"
        ></el-table-column>
         <el-table-column
          prop="store_state"
          label="状态"
          key="store_state"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="member_id"
          label="账号id"
          key="member_id"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="member_name"
          label="账号名称"
          key="member_name"
          :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column
          prop="store_show"
          label="APP/微信预约显示"
          min-width="130"
          key="store_show"
          :show-overflow-tooltip="true"
        >
        <template slot-scope="scope">
          <!-- `checked` 为 true 或 false -->
          <el-checkbox v-model="scope.row.store_show" @change="updatebox(scope.row.store_id,scope.row.store_show)"></el-checkbox>
        </template>        
        </el-table-column>
        
         <el-table-column
          prop="store_point_power"
          label="积分管理权限"
          min-width="104"
          key="store_point_power"
          :show-overflow-tooltip="true"
        >
        <template slot-scope="scope">
          <!-- `checked` 为 true 或 false -->
          <el-checkbox v-model="scope.row.store_point_power" @change="modifyPointPower(scope.row.store_id,scope.row.store_point_power)"></el-checkbox>
        </template> 
        </el-table-column>
         <el-table-column
          prop="store_end_time"
          label="到期时间"
          key="store_end_time"
          :show-overflow-tooltip="true"
        ></el-table-column>
         <el-table-column
          prop="usage_status"
          label="使用状态"
          key="usage_status"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column fixed="right" align="center" label="操作" key="operate" width="160">
          <template slot-scope="scope">
						<el-dropdown size="mini" trigger="click">
						  <el-button type="primary">
  						      展开<i class="el-icon-arrow-down el-icon--right"></i>
  						  </el-button>
						  <el-dropdown-menu slot="dropdown" class="dropdown-btn el-dropdown__button-group">
						    <el-dropdown-item>
                  <el-button
                    class="operateBtn"
                    type="text"
                    @click="jumpSetting(scope.row.depart_id, scope.row.store_id, scope.row.store_name)">
                    权限
                  </el-button>
                </el-dropdown-item>
						    <el-dropdown-item>
                  <el-button class="operateBtn" type="text" @click="deleter(scope.row.store_id)">删除</el-button>
                </el-dropdown-item>
						    <el-dropdown-item>
                  <el-button class="operateBtn" type="text" @click="edit(scope.row.store_id)">编辑</el-button>
                </el-dropdown-item>
						    <el-dropdown-item>
                  <el-button class="operateBtn" type="text" @click="handleAnnualFee(scope.row.store_id)">服务年费</el-button>
                </el-dropdown-item>
						    <!-- <el-dropdown-item>
                  <el-button class="operateBtn" type="text" @click="handleQuota(scope.row.store_id)">授信额度</el-button>
                </el-dropdown-item> -->
						    <el-dropdown-item>
                  <el-button class="operateBtn" type="text" @click="showFn(scope.row.id)">进件</el-button>
                </el-dropdown-item>
						    <el-dropdown-item>
                  <el-button class="operateBtn" type="text" @click="addEnterpriseConfig(scope.row.store_id)">企微</el-button>
                </el-dropdown-item>
						  </el-dropdown-menu>
						</el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :arr="aList"
        :total="total"
        :currentPage="currentPage"
        :handleSizeChange="handleSizeChange"
        :handleCurrentChange="handleCurrentChange"
      ></pagination>
    </div>
    <default-opr ref="ceshi"></default-opr>
    <enterprise-config ref="enterprise"></enterprise-config>
    <annual-fee-dialog :visible.sync="visible" :id="rowId"></annual-fee-dialog>
    <quota-dialog :visible.sync="visible_quota" :id="rowId"></quota-dialog>
  </div>
</template>
<script>
import pagination from "@/components/pagination/pagination.vue";
import { resize } from "@/common/js/height.js";
import defaultOpr from './default-opr'
import EnterpriseConfig from './enterpriseConfig.vue';
import AnnualFeeDialog from './annual-fee-dialog.vue';
import QuotaDialog from './quota-dialog.vue';
export default {
  data() {
    return {
      searchObj: {
        //该变量定义查询传参
        pageSize: 10,
        page: 1,
        store_name: "",
        member_name: "",
        depart_id:"",
        store_owner: ""
        
      },
      aList: [],
      group: [],
      oHeight: 800,
      total: 1,
      currentPage: 1,
      visible: false,
      visible_quota: false,
      rowId: 0
    };
  },
  components: {
    pagination,
    defaultOpr,
    EnterpriseConfig,
    AnnualFeeDialog,
    QuotaDialog
  },
  created(){},
  methods: {
    // 获取列表
    getList() {
      var that = this;
      this.searchObj.curpage = that.currentPage;
      this.$http
        .post(
          "/admin/auth/index.php?act=storesPermission&op=myStoreList",
          this.searchObj
        )
        .then(
          res => {
            if (res.code == 1) {
              this.aList = res.data.list.map(function(item) {
						        return {
                      depart_id: parseInt(item.depart_id),
                      store_id:item.store_id,
                      store_name:item.store_name,
                      first_depart_name:item.first_depart_name,
                      member_id:item.member_id,
                      member_name:item.member_name,
                      store_owner:item.store_owner,
                      store_show: item.store_app_show=='是'?true:false,
                      store_state:item.store_state,
                      store_point_power:item.store_point_power == '是'?true:false,
                      store_end_time:item.store_end_time,
                      usage_status:item.usage_status,


						        }
							});
              this.total = parseInt(res.data.totalCount);
            } else {
              this.$message.error("获取数据失败！");
              // alert(res.msg);
              this.aList = [];
            }
          },
          err => {
            this.$message.error("获取数据失败！");
          }
        );
    },
    // 搜索
    search() {
      //1、获取搜索的内容
      this.currentPage = 1;
      this.searchObj.page = 1;
      //2、获取内容列表
      this.getList();
    },
    showFn(data){
      // console.log("data",data);
			this.$refs.ceshi.show_dialog_fn(data);
    },
    addEnterpriseConfig(storeId){
			this.$refs.enterprise.init(storeId);
		},
     // 获取集团列表
    getGroup() {
      this.$http
        .post("/admin/depart/index.php?act=departManage&op=firstDeparts")
        .then(res => {
          if (res.code == 1) {
            this.group = res.data;
          }
        });
    },
    // 重置
    reset() {
      //1、清空搜索的内容
      this.searchObj.store_name = "";
      this.searchObj.member_name = "";
      this.searchObj.store_owner = "";
      this.searchObj.page = 1;
      this.searchObj.depart_id = "";
      this.currentPage = 1;
      //2、获取内容列表
      this.getList();
    },
    // 跳转权限编辑
    jumpSetting(depart_id, store_id, store_name) {
      this.$router.push({
        path: "/home/control-panel/power-setting",
        query: {
          id: store_id,
          name: store_name,
          depart_id,
        }
      });
    },
    // 修改是否展示店铺
    updatebox(storeid,state){
      if(state){
       var status = 1
      }else{
       var status = 0
      }
				this.$http.post('/admin/store/index.php?act=storeManage&op=updateStoreShow',{store_id:storeid,store_app_show:status}).then((res)=>{
					if(res.code===1){
            
					}else{
            alert(res.msg);
          }
				})         
    },
    // 修改积分权限
    modifyPointPower(storeid,state){
      console.log(storeid, state)
      if(state){
       var status = 1
      }else{
       var status = 0
      }
				this.$http.post('/admin/store/index.php?act=storeManage&op=modifyPointPower',{store_id:storeid,store_point_power:status}).then((res)=>{
					if(res.code===1){
            this.$message({
              message: '修改成功',
              center: true,
              type: 'success'
            });
					}else{
            this.$message({
              message: res.msg,
              center: true,
              type: 'error'
            });
          }
				})         
    },
    // 删除店铺
    deleter(id) {
      this.$confirm("确认删除？")
        .then(_ => {
          this.$http
            .post("/admin/store/index.php?act=storeManage&op=delStore", {
              store_id: id
            })
            .then(
              res => {
                if (res.code == 1) {
                  this.$message({
                    showClose: true,
                    message: res.msg,
                    type: "success"
                  });
                  this.reset();
                } else {
                  this.$message({
                    showClose: true,
                    message: res.msg,
                    type: "error"
                  });
                }
              },
              err => {
                this.$message({
                  showClose: true,
                  message: res.msg,
                  type: "error"
                });
              }
            );
          done();
        })
        .catch(_ => {});
    },
    // 点击编辑
    edit(id, name) {
      this.$router.push({
        path: "shop-edit",
        query: {
          id: id
        }
      });
    },
    // 改变当前页
    handleCurrentChange: function(val) {
      this.searchObj.page = val;
      this.currentPage = val;
      /*请求数据*/
      this.getList();
    },
    //分组一页多少数据
    handleSizeChange(val) {
      this.currentPage = 1;
      this.searchObj.page = 1;
      this.searchObj.pageSize = val;
      /*请求数据*/
      this.getList();
    },
    handleAnnualFee(id) {
      this.visible = true
      this.rowId = +id
    },
    handleQuota(id) {
      this.visible_quota = true
      this.rowId = +id
    }
  },
  mounted() {
    //页面刷新就执行
    localStorage.eachNum = "";
    this.getList();
    this.getGroup(); //获取集团
    resize(this);
  },
  activated() {
    localStorage.eachNum = "";
    this.getList();
    resize(this);
    this.$nextTick(() => {
      this.$refs.table.doLayout(); //解决表格错位
    });
  }
};
</script>

<style scoped lang="scss">
.operateBtn { margin-right: 0;}
</style>
